package cn.wk.org.controller;

import cn.wk.basic.query.DetailQuery;
import cn.wk.basic.query.DictQuery;
import cn.wk.basic.utils.AjaxResult;
import cn.wk.basic.utils.PageBean;
import cn.wk.org.domain.DictionaryDetail;
import cn.wk.org.domain.DictionaryType;
import cn.wk.org.service.IDictionaryDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/dictionaryDetail")
public class DictionaryDetailController {
    @Autowired
    private IDictionaryDetailService detailService;

    @PostMapping
    public PageBean<DictionaryDetail> findAll(@RequestBody DetailQuery detailQuery){
        System.out.println(detailQuery);
        return detailService.queryAll(detailQuery);
    }

    @PutMapping
    public AjaxResult save(@RequestBody DictionaryDetail dictionaryDetail){
        System.out.println(dictionaryDetail);
        try{
            if(dictionaryDetail.getId() == null){
                detailService.save(dictionaryDetail);
            }else{
                detailService.update(dictionaryDetail);
            }
            return new AjaxResult();
        }catch(Exception e){
            return new AjaxResult("错误");
        }
    }

    @DeleteMapping("/{id}")
    public AjaxResult del(@PathVariable Long id){
        System.out.println(id);
        try{
            detailService.deleteByid(id);
            return new AjaxResult();
        }catch(Exception e){
            return new AjaxResult("删除失败");
        }
    }
}
